#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <math.h> 
#include <ctype.h> 
#include <time.h> 
#include <assert.h>

int main()
{
	int n = 0;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
	{
		int temp1 = i;
		int temp2 = i;
		int sum = 0;
		int wei = 0;

		while (temp1)
		{
			wei++;
			temp1 /= 10;
		}
		
		while (temp2)
		{
			int num = temp2 % 10;
			sum += pow(num, wei);
			temp2 /= 10;
		}

		if (sum == i)
		{
			printf("%d ", sum);
		}
	}
	
	return 0;
}